const http = require('http')
const server = http.createServer()
server.on('request',(req,res)=>{
    const url = req.url
    const method = req.method
    // 2. 设置默认的响应内容为 404 Not found
    let content = '<h1>404 Not found!</h1>'
    if (url === '/' || url === '/index.html'){
        content = '<h1>首页</h1>'
    }else if(url === '/about.html'){
        content = '<h1>关于页码</h1>'
    }
    const str = `<!--<h2>Your request url is ${url}, and request method is ${method},这个是中文的</h2>-->`
    res.statusCode = 200
    // 调用 res.setHeader() 方法，设置 Content-Type 响应头，解决中文乱码的问题
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    res.end(content)
})
server.listen(8888,()=>console.log('server running at http://127.0.0.1:8888'))